package com.sofar.gems.framework.controller;

import com.sofar.gems.framework.entity.SysRole;
import com.sofar.gems.framework.entity.SysUrl;
import com.sofar.gems.framework.service.SysUrlService;
import com.sofar.gems.framework.vo.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @description: 网址信息控制器
 * @company: yaorange
 * @author: 啊啊啊林
 * @version: 1.0
 * @create: 2021-09-21 20:07:01
 */
@RestController
@RequestMapping("/url")
public class SysUrlController {
    @Autowired
    private SysUrlService sysUrlService;

    @GetMapping
    public R<?> selectAll() {
        List<SysUrl> all = sysUrlService.selectAll();
        return R.success(all);
    }

    /**
    * @description:添加网址
    * @param sysUrl 网址就行
    * @return com.sofar.gems.framework.vo.R<?>
    * @exception
    */
    @PostMapping
    public R<?> insert(@RequestBody SysUrl sysUrl) {
        int i = sysUrlService.insertSelective(sysUrl);
        if (i > 0) {
            return R.success("success");
        } else {
            return R.error("插入失败");
        }
    }
/**
* @description:主键删除
* @param urlId
* @return com.sofar.gems.framework.vo.R<?>
* @exception
*/
    @DeleteMapping("/{urlId}")
    public R<?> delete(@PathVariable Integer urlId ) {
        int i = sysUrlService.deleteByPrimaryKey(urlId);
        if (i > 0) {
            return R.success("success");
        } else {
            return R.error("删除失败");
        }
    }

/**
* @description:非全参修改
* @param sysUrl
* @return com.sofar.gems.framework.vo.R<?>
* @exception
*/
    @PutMapping
    public R<?> update(@RequestBody SysUrl sysUrl) {
        int i = sysUrlService.updateByPrimaryKeySelective(sysUrl);
        if (i > 0) {
            return R.success("修改成功");
        } else {
            return R.error("修改失败");
        }
    }
}
